package sanshui.system.trade.factory.notify.channelImpl;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Component;
import sanshui.system.trade.common.GlobalContain;
import sanshui.system.trade.factory.notify.AbstractTradeSysNotify;
import sanshui.system.trade.factory.notify.TradeSysNotify;
import sanshui.system.trade.factory.notify.TradeSysNotifyModel;
import sanshui.system.trade.util.PushPlusUtil;

@Component
@Slf4j
public class GongZongHaoNotifyImpl extends AbstractTradeSysNotify {
    @Override
    public String getNotifyChannel() {
        return GlobalContain.NotifyChannel.Gong_Zong_Hao.name();
    }

    @Override
    public boolean execute(TradeSysNotifyModel notifyModel) {
        try {
            PushPlusUtil.PushPlusModel pushPlusModel = new PushPlusUtil.PushPlusModel();
            String toSomeJsonStr = notifyModel.getToSomeJsonStr();

            if (Strings.isNotEmpty(toSomeJsonStr)){
                pushPlusModel = JSONObject.parseObject(toSomeJsonStr, PushPlusUtil.PushPlusModel.class);
            }
            // 发送消息
            pushPlusModel.setTitle(notifyModel.getTitle());
            pushPlusModel.setContent(notifyModel.getOriContent());
            pushPlusModel.setTopic("Watery_Trade");
            pushPlusModel.setTemplate("txt");
            return PushPlusUtil.send(pushPlusModel);
        } catch (Exception e) {
            log.info("PushPlus发送失败", e);
            return false;
        }
    }
}
